package com.example.studentportrait.service.impl;

import com.example.studentportrait.domain.entity.JobRecruitment;
import com.example.studentportrait.mapper.JobRecruitmentMapper;
import com.example.studentportrait.service.JobRecruitmentService;
import com.example.studentportrait.utils.Pagebean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Service
public class JobRecruitmentServiceImpl implements JobRecruitmentService {
    @Resource
    JobRecruitmentMapper jobRecruitmentMapper;
    @Override
    public int addJobRecruitment(JobRecruitment jobRecruitment) {
        jobRecruitmentMapper.insert(jobRecruitment);
        return 0;
    }

    @Override
    public int updateJobRecruitment(JobRecruitment jobRecruitment) {
        jobRecruitmentMapper.updateById(jobRecruitment);
        return 0;
    }

    @Override
    public Pagebean getAll(int page, int pagesize) {
        PageHelper.startPage(page, pagesize); // 开启分页查询
        List<JobRecruitment> audit = jobRecruitmentMapper.selectAll(); // 执行查询，此时返回的是分页后的List
        // 使用PageInfo来获取分页信息
        PageInfo<JobRecruitment> pageInfo = new PageInfo<>(audit);
        // 假设你有一个自定义的pagebean类
        Pagebean pb = new Pagebean();
        pb.setTotal(pageInfo.getTotal()); // 设置总记录数
        pb.setItems(Collections.singletonList(audit)); // 设置结果列表
        return pb;
    }

    @Override
    public Pagebean getByName(String jobName, int page, int pagesize) {
        PageHelper.startPage(page, pagesize); // 开启分页查询
        List<JobRecruitment> audit = jobRecruitmentMapper.selectByName(jobName); // 执行查询，此时返回的是分页后的List
        // 使用PageInfo来获取分页信息
        PageInfo<JobRecruitment> pageInfo = new PageInfo<>(audit);
        // 假设你有一个自定义的pagebean类
        Pagebean pb = new Pagebean();
        pb.setTotal(pageInfo.getTotal()); // 设置总记录数
        pb.setItems(Collections.singletonList(audit)); // 设置结果列表
        return pb;
    }

    @Override
    public Pagebean getByRequired(String required, int page, int pagesize) {
        PageHelper.startPage(page, pagesize); // 开启分页查询
        List<JobRecruitment> audit = jobRecruitmentMapper.selectByRequired(required); // 执行查询，此时返回的是分页后的List
        // 使用PageInfo来获取分页信息
        PageInfo<JobRecruitment> pageInfo = new PageInfo<>(audit);
        // 假设你有一个自定义的pagebean类
        Pagebean pb = new Pagebean();
        pb.setTotal(pageInfo.getTotal()); // 设置总记录数
        pb.setItems(Collections.singletonList(audit)); // 设置结果列表
        return pb;
    }

    @Override
    public Pagebean getByMajor(String jobMajor, int page, int pagesize) {
        PageHelper.startPage(page, pagesize); // 开启分页查询
        List<JobRecruitment> audit = jobRecruitmentMapper.selectByMajor(jobMajor); // 执行查询，此时返回的是分页后的List
        // 使用PageInfo来获取分页信息
        PageInfo<JobRecruitment> pageInfo = new PageInfo<>(audit);
        // 假设你有一个自定义的pagebean类
        Pagebean pb = new Pagebean();
        pb.setTotal(pageInfo.getTotal()); // 设置总记录数
        pb.setItems(Collections.singletonList(audit)); // 设置结果列表
        return pb;
    }
}
